#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#define all(e) e.begin(), e.end()
//#define int unsigned long long
#define int long long
using namespace std;

signed main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		map<int, int> cnt;
		while (n--)
		{
			int tmp; cin >> tmp;
			cnt[tmp]++;
		}
		vector<int> arr;
		for (auto& e : cnt) arr.push_back(e.second);
		sort(all(arr));
		int ans = 0, size = arr.size();
		for (int i = 0; i < size; ++i)
		{
			ans = max(ans, (size - i) * arr[i]);
		}
		cout << ans << endl;
	}
	return 0;
}

//4 5 1 1 4 4 4 2 1 2 15 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5 5 3 3 3 3 3

//2 3
//
//1 1
//
//5 4 3 2 1
//
//5